<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>苹果后台</title>
<script type="text/javascript" src="${path}/js/back/jquery.min.js"></script>
<script type="text/javascript"
	src="${path}/js/back/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${path}/js/back/easyui-lang-zh_CN.js"></script>
<script type="text/javascript"
	src="${path}/js/back/datagrid-detailview.js"></script>
<link rel="stylesheet" href="${path}/css/back/themes/default/easyui.css"
	type="text/css" />
<link rel="stylesheet" href="${path}/css/back/themes/icon.css"
	type="text/css" />
<link rel="stylesheet" type="text/css"
	href="${path}/css/back/demo.css">
	 <style type="text/css"> 
        #fm 
        { 
            margin: 0; 
            padding: 10px 30px; 
        } 
        .ftitle 
        { 
            font-size: 14px; 
            font-weight: bold; 
            padding: 5px 0; 
            margin-bottom: 10px; 
            border-bottom: 1px solid #ccc; 
        } 
        .fitem 
        { 
            margin-bottom: 5px; 
        } 
        .fitem label 
        { 
            display: inline-block; 
            width: 80px; 
        } 
    </style> 
</head>
<body>
<script type="text/javascript">
		var data = ${data};
 $(function(){
	    	$('#dg').datagrid({
	    		/* url:"${path}/manager/toUserEditInit", */
	    		fitColumns:true,//列自适应宽度，不能和冻结列同时设置为true
	    	        striped:true,//斑马线效果
	    	        idField:'UID',//主键列
	    	        rownumbers:true,//显示行号
	    	        singleSelect:true,//是否单选
	    	        pagination:true,//显示分页栏
	    	        pageList:[10,20,50,100],//每页行数选择列表
	    	        pageSize:10,//出事每页行数
	    	        remoteSort:true,//是否服务器端排序，设成false，才能客户端排序
	    	        sortName:'UID',//设置排序列
	    	        sortOrder:'desc',//排序方式
	    	    columns:[[
	    	        {field:'uID',title:'编号',width:100},
	    	        {field:'uName',title:'账户名',width:100},
	    	        {field:'uLoginId',title:'账号',width:100},
	    	        {field:'uLoginPsw',title:'密码',width:100},
	    	        {field:'uAddress',title:'收货地址',width:150},
	    	        {field:'uPhoneNum',title:'电话',width:150}
	    	    ]],
	    	     toolbar:[{
	    	    	    text:'新增',
	    	    	    iconCls: 'icon-add',
	    	    	    handler: function(){
	    	    	    	add();
	    	    	    }
	    	    	    },'-',{
	    	    	    	text:'修改',
	        	    	    iconCls: 'icon-edit',
	        	    	    handler: function(){
	        	    	    	update();
	        	    	    }
	    	    	    },'-',{
	    	    	    	text:'删除',
	    	    	    	iconCls: 'icon-remove',
	        	    	    handler: function(){
	        	    	    	destroyUser();
	        	    	    }
	    	    	    }]
	    	});
	    });
 function add() {
	 $("#dlg").dialog("open").dialog('setTitle', '新增用户');
	 $("#fm").form("clear");
}
 function save() {
     $("#fm").form("submit", {
         url: "${path}/manager/AddUser",
         onsubmit: function () {
             return $(this).form("validate");
         },
         success: function (result) {
             if (result) {
                 $.messager.alert("提示信息", "操作成功");
                 $("#dlg").dialog("close");
                 $("#dg").datagrid("load");
             }else {
                 $.messager.alert("提示信息", "操作失败");
             }
         }
     });
 }
 function saveuser() {
	 var row = $('#dg').datagrid('getSelected');
	 $("#fmm").form("submit", {
         url: url = "manager/UpdateUser?uID=" + row.uID,
         onsubmit: function () {
             return $(this).form("validate");
         },
         success: function (result) {
             if (result) {
                 $.messager.alert("提示信息", "修改成功");
                 $("#dllg").dialog("close");
                 $("#dg").datagrid("load");
             }else {
                 $.messager.alert("提示信息", "操作失败");
             }
         }
     });
}
function update(){
	var row = $('#dg').datagrid('getSelected');
	if(row){
		$("#dllg").dialog("open").dialog('setTitle', '更新用户');
		$("#fmm").form("clear");
		$("#fmm").form("load", row);
         url = "manager/UpdateUserUI?uID=" + row.uID;
	}
}
function destroyUser() {
    var row = $('#dg').datagrid('getSelected');
    if (row) {
        $.messager.confirm('Confirm', '您确认删除吗?', function (r) {
            if (r) {
                $.post('manager/DeleteUser?uID='+row.uID, function (json) {
                		 $.messager.alert("提示信息", "删除成功");
                		 $("#dlg").dialog("close");
                		 $("#dg").datagrid("load");
                });
            }
        });
    }else{
   	 $.messager.alert("提示信息", "请选择要删除的数据");
    }
}  
	</script>
<!-- data-options="data:data" -->
	<table id="dg" class="easyui-datagrid" title="用户管理"
		style="width: 700px; height: 365px" toolbar="#toolbar"
		data-options="data:data"
		pagination="true" fitColumns="true" singleSelect="true">
	</table>
	<div id="dlg" class="easyui-dialog" style="width: 500px; height: 300px; padding: 10px 20px;" closed="true" buttons="#dlg-buttons"> 
		       <form id="fm" method="post">
		       <div class="fitem"> 
		           账户名<input id="uName" name="uName" class="easyui-validatebox"/> 
		       </div> 
		       <div class="fitem"> 
		            账号 <input id="uLoginId" name="uLoginId"  class="easyui-validatebox"/> 
		       </div> 
		       <div class="fitem"> 
		           密码	<input id="uLoginPsw" name="uLoginPsw" class="easyui-vlidatebox"/> 
		       </div> 
		           <div class="fitem"> 
		           收货地址	<input id="uAddress" name="uAddress" class="easyui-vlidatebox"/> 
		       </div> 
		          <div class="fitem"> 
		           手机号	<input id="uPhoneNum" name="uPhoneNum" class="easyui-vlidatebox"/> 
		       </div> 
		       </form> 
		</div>
		<div id="dlg-buttons"> 
	        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="save()" iconcls="icon-save">保存</a> 
	        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#dlg').dialog('close')"
	            iconcls="icon-cancel">取消</a> 
	</div>
	<div id="dllg" class="easyui-dialog" style="width: 500px; height: 300px; padding: 10px 20px;" closed="true" buttons="#dlg-buttons"> 
		       <form id="fmm" method="post">
		       <div class="fitem"> 
		           账户名<input id="uName" name="uName" class="easyui-validatebox"/> 
		       </div> 
		       <div class="fitem"> 
		            账号 <input id="uLoginId" name="uLoginId"  class="easyui-validatebox"/> 
		       </div> 
		       <div class="fitem"> 
		           密码	<input id="uLoginPsw" name="uLoginPsw" class="easyui-vlidatebox"/> 
		       </div> 
		           <div class="fitem"> 
		           收货地址	<input id="uAddress" name="uAddress" class="easyui-vlidatebox"/> 
		       </div> 
		          <div class="fitem"> 
		           手机号	<input id="uPhoneNum" name="uPhoneNum" class="easyui-vlidatebox"/> 
		       </div> 
		       <input type="hidden" name="uID" id="uID" /> 
		       </form> 
		</div>
	<div id="dlg-buttons"> 
	        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="saveuser()" iconcls="icon-save">保存</a> 
	        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#dllg').dialog('close')"
	            iconcls="icon-cancel">取消</a> 
	</div>
</body>
</html>